cc.Class({
    extends: cc.Component,

    properties: {
        moregames: cc.Node,
        MoreGamesNode: cc.Node,
        range: cc.Node,
        Score: cc.Label,
        GameStart: cc.Node,
        animate: cc.Sprite,
        play: cc.Node,
        over: cc.Node,
        timeOver: cc.Node,
        gameOver: cc.Node,
        GameEnd: cc.Node,
        timeoverLabel: cc.Node,
        gameoverLanel: cc.Node,
        Scored: cc.Label,
        Best: cc.Label,
        Again: cc.Node,
        Share: cc.Node,
    },

    // use this for initialization
    onLoad: function () {
        this.rangeTimer = this.range.getComponent("LibStarGame_range");
    },
    init(image){
        this.animateInit(image);
        this.moregamesClick();
        this.AgainClick();
        this.nodeInit();
        this.playClick();
        this.ShareClick();
        cc.gameStartFn = function(){
            self.StartGame();
        }
    },

    nodeInit: function(){
        var w = cc.find("Canvas").width, h = cc.find("Canvas").height;
        cc.find("LibStarGame").x = w / 2;
        cc.find("LibStarGame").y = h / 2; 
    },

    moregamesClick(){
        this.moregames.on("click", function(){
            this.moreEven();
        }, this)
    },

    AgainClick(){
        this.Again.on("click", function(){
            cc.gameStart.Score = 0;
            cc.director.loadScene(cc.director.getScene().name);
        }, this)
    },

    ShareClick(){
        this.Share.on("click", function(){
            cc.sdkbox.shareAsync(cc.gameStart.gameName, cc.gameStart.Score);
        }, this)
    },

    playClick(){
        this.play.on("click", function(){
            this.StartGame();
        }, this)
    },

    moreEven(){
        this.MoreGamesNode.active = true;
        this.MoreGamesNode.getComponent("LibStarGame_moreGames").init();
    },

    animateInit(image){
        if(image){
            this.animate.spriteFrame = image;
        }
    },

    StartGame(){
        this.Score.node.active = true;
        this.GameStart.active = false;
        this.Score.string = cc.gameStart.Score;
        cc.bgm.play();
        cc.gameStart.gameStart();
    },

    timeOverEven(scoreEnd, BestScore){
        this.timeoverLabel.active = true;
        this.overEven(scoreEnd, BestScore);
    },

    gameOverEven(scoreEnd, BestScore){
        this.gameoverLanel.active = true;
        this.overEven(scoreEnd, BestScore)
    },

    overEven(scoreEnd, BestScore){
        this.Scored.string = scoreEnd;
        this.Best.string = "Best Score " + BestScore;
        this.GameEnd.active = true;
    },

    rangeTimerInit(img1, img2){
        this.rangeTimer.init(img1,img2);
    },

    rangeTimerStartTime(num,bol){
        if(!num) var num = 1;
        this.range.active = true;
        if(bol){
            this.rangeTimer.SecondsStart(num);//数字的倒计时
        }else{
            this.rangeTimer.startTime(num);//进度条的倒计时
        }
    },

    rangeTimerEndTime(){
        this.range.active = false;
        return this.rangeTimer.endTime();
    },
    ScoreAnimation(){
        if(this.Score){
             var anim = this.Score.node.getComponent(cc.Animation);
            anim.play();
        }
    },
    setScore(num){
        if(this.Score){
            this.Score.string = num;
        }
    },

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {
       
    // },
});
